/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cz.uhk.ppro.traveler.entity;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;

/**
 *
 * @author dusi
 */
@Entity
public class TTransaction implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date tDate;
    private float amount;
    private int type;       // 1 - income | 0 - expense //??? proc -1 na expense
    private String description;

    // Relationships
    @ManyToOne
    private TBudget budget;

    // Constructor
    public TTransaction() {

        this.amount = 0;
        this.type = 0;
    }

    public TTransaction(float amount, int type, TBudget budget) {

        this.amount = amount;
        this.type = type;
        this.budget = budget;
    }
    
    public TTransaction(Date tDate, float amount, int type, TBudget budget) {
        
        this.tDate = tDate;
        this.amount = amount;
        this.type = type;
        this.budget = budget;
    }

    // Accessors
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Date gettDate() {
        return tDate;
    }

    public void settDate(Date tDate) {
        this.tDate = tDate;
    }

    public float getAmount() {
        return amount;
    }

    public void setAmount(float amount) {
        this.amount = amount;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public TBudget getBudget() {
        return budget;
    }

    public void setBudget(TBudget budget) {
        this.budget = budget;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }
    
    // General
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof TTransaction)) {
            return false;
        }
        TTransaction other = (TTransaction) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "cz.uhk.ppro.traveler.entity.TTransaction[id=" + id + "]";
    }
}
